<!DOCTYPE html>
<html>
<body>
<div id="message"></div>
<script>

const message = document.getElementById('message');

const fetch = url => new Promise((resolve, reject) => {
  const xhr = new XMLHttpRequest();
  xhr.onreadystatechange = () => {
    if (xhr.readyState === XMLHttpRequest.DONE) {
      if (xhr.status === 200) resolve(xhr.responseText);
      else reject(`Status Code: ${xhr.status}`);
    }
  };
  xhr.open('GET', url, true);
  xhr.send();
});

// Usage

fetch('/person')
  .then(body => message.innerHTML = body)
  .catch(err => message.innerHTML = err);

</script>
</body>
</html>
